<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="110px">
      <!--<el-form-item label="发货通知编码" prop="nos">
        <el-input v-model="queryParams.nos" placeholder="请输入发货通知编码" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>-->
      <el-form-item label="订单编号" prop="projectNos">
        <el-input v-model="queryParams.projectNos" placeholder="请输入订单编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="交货日期">
        <el-date-picker v-model="dateRange" style="display: flex;" value-format="yyyy-MM-dd" type="daterange"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item label="联系人" prop="linkman">
        <el-input v-model="queryParams.linkman" placeholder="请输入联系人" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="联系电话" prop="linktel">
        <el-input v-model="queryParams.linktel" placeholder="请输入联系电话" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!--<el-form-item label="收货地址" prop="address">
                <el-input v-model="queryParams.address" placeholder="请输入收货地址"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>-->
      <el-form-item label="业务经理及电话" prop="jingli">
        <el-input v-model="queryParams.jingli" placeholder="请输入业务经理及电话" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="客户名称" prop="kehuName">
        <el-input v-model="queryParams.kehuName" placeholder="请输入客户名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

     <!-- <el-form-item label="项目负责人" prop="">
        <el-input v-model="queryParams." placeholder="请输入项目负责人" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="项目单位" prop="">
        <el-input v-model="queryParams." placeholder="请输入项目单位" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="工程名称" prop="">
        <el-input v-model="queryParams." placeholder="请输入工程名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="业务员" prop="">
        <el-input v-model="queryParams." placeholder="请输入业务员" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="制单人" prop="">
        <el-input v-model="queryParams." placeholder="请输入制单人" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
     <!-- <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">-->
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                   v-if="!projectCode"    v-hasPermi="['develop:LvFahuotongzhi:add']">新增发货通知</el-button>
          </el-form-item>
      <!-- </el-col>
     </el-row>-->
    </el-form>

    <!--<el-row :gutter="10" class="mb8">
          <el-col :span="1.5">

          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>-->
    <el-table border v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" ref="table"
      :max-height="tableMaxHeight" @sort-change="handleSortChange">
      <el-table-column type="selection" width="55" align="center" />
      <!--<el-table-column sortable label="发货通知编码" align="center" prop="nos" width="150"/>-->
      <el-table-column sortable label="订单编号" align="center" prop="projectNos" show-overflow-tooltip />
      <el-table-column sortable label="客户名称" align="center" prop="kehuName" show-overflow-tooltip />
      <el-table-column sortable label="交货日期" align="center" prop="jiaohuoDate" />
      <el-table-column sortable label="联系人" align="center" prop="linkman" />
      <el-table-column sortable label="联系电话" align="center" prop="linktel" />
      <el-table-column sortable label="业务经理及电话" align="center" prop="jingli" show-overflow-tooltip />
      <el-table-column sortable label="收货地址" align="center" prop="address" show-overflow-tooltip />
      <el-table-column label="备注" align="center" prop="remark" show-overflow-tooltip />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-tickets" @click="tongzhidan(scope.row)">通知单明细</el-button>
          <el-button size="mini" type="text" icon="el-icon-s-promotion"
            @click="handleMingxi(scope.row)">生成发货单</el-button>
          <el-button size="mini" type="text" icon="el-icon-document-copy" @click="fahuodan(scope.row)">发货单记录</el-button>
          <el-popconfirm :title="`确认删除当前数据项？`" @confirm="handleDelete(scope.row)" style="margin-left: 10px;">
            <el-button slot="reference" size="mini" type="text" icon="el-icon-delete"
              v-hasPermi="['develop:LvFahuotongzhi:remove']">删除</el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <lvFahuotongzhi-form ref="form" @ok="getList"></lvFahuotongzhi-form>
    <fahuodan-list ref="fahuodanList" @ok="getList"></fahuodan-list>
    <tongzhidan-list ref="tongzhidanList" @ok="getList"></tongzhidan-list>
    <lvFahuotongzhi-formList ref="formList" @ok="getList"></lvFahuotongzhi-formList>
  </div>
</template>

<script>
  import {
    deleteAction,
    getAction
  } from '@/api/manage'
  import LvFahuotongzhiFormList from '@/views/develop/lvFahuotongzhi/module/LvFahuotongzhiFormList'
  import LvFahuotongzhiForm from '@/views/develop/lvFahuotongzhi/module/LvFahuotongzhiForm'
  import FahuodanList from '@/views/develop/lvFahuotongzhi/module/FahuodanList'
  import TongzhidanList from '@/views/develop/lvFahuotongzhi/module/TongzhidanList'
  import {
    list
  } from "@/api/develop/lvFahuotongzhi";

  export default {
    /*dicts: [  'fahuotongzhi_state'],*/
    name: "LvFahuotongzhiList",
    components: {
      LvFahuotongzhiFormList,
      LvFahuotongzhiForm,
      FahuodanList,
      TongzhidanList
    },
    props: {
            projectCode: {
                type: [String],
                required: true,
                default: ''
            },
        },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 出货通知单表格数据
        dataList: [],
        dateRange: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          nos: null,
          projectNos: null,
          name: null,
          jiaohuoDate: null,
          linkman: null,
          linktel: null,
          address: null,
          status: null,
          jingli: null,
          kehuId: null,
          kehuName: null,
          taxNo: null,
          taxCode: null,
          taxDate: null,
          taxMoney: null,
          taxShengyu: null,
          taxAllmoeny: null,
          allMoney: null,
          shengyu: null,
          yihui: null,
          orderByColumn: "nos",
          isAsc: "desc"
        },
        url: {
          list: '/lvFahuotongzhi/lvFahuotongzhi/list',
          remove: '/lvFahuotongzhi/lvFahuotongzhi/',
          export: '/lvFahuotongzhi/lvFahuotongzhi/export',
        },
        tableMaxHeight: window.innerHeight - 320,
      };
    },
    watch: {
            'projectCode': {
                handler(newVal, oldVal) {
                  console.log("projectCode", newVal);
                    if (newVal) {
                        this.queryParams.projectNos = newVal;
                        this.getList();
                    }
                },
                deep: true,
                immediate: true
            },
        },
    created() {
      this.getList();
      window.addEventListener('resize', this.getTableHeight);
    },
    destroyed() {
      window.removeEventListener('resize', this.getTableHeight)
    },
    methods: {
        /** 排序触发事件 */
    handleSortChange(column, prop, order) {
      this.queryParams.orderByColumn = column.prop;
      this.queryParams.isAsc = column.order;
      this.handleQuery();
    },
      fahuodan(row) {
        this.$refs.fahuodanList.showFahuodanList(row);
      },
      tongzhidan(row) {
        this.$refs.tongzhidanList.showTongzhidanList(row);
      },
      showChild(row) {
        this.$refs.showForm.showTongzhiList(row);
      },
      /** 查询出货通知单列表 */
      getList() {
        this.loading = true;
        list(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.dataList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      getTableHeight() {
        this.tableHeight = window.innerHeight - 320
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.dateRange = [];
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.$refs.form.handleAdd();
      },
      /** 修改按钮操作 */
      handleMingxi(row) {
        this.$refs.formList.handleMingxiShow(row);
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        deleteAction(this.url.remove, ids).then(response => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download(this.url.export, {
          ...this.queryParams
        }, `lvFahuotongzhi_${new Date().getTime()}.xlsx`)
      },
    }
  };
</script>
